//
//  DYLocationDelegate.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/3/18.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit
import SwiftWeb

class DYLocationDelegate: LocationProtocol {
    
    var location:LocationManager!
    
    var gpsClosure:((Double, Double)->Void)?
    
    var locationClosure:((String,String,String,String,String)->Void)?
    
    var currentVC: UIViewController!
    
    var isOnece: Bool!
    
    func getGPSAuthorizationFailure() {
        let alert = UIAlertController(title: "提示", message: "请打开定位，以便获取您的位置信息", preferredStyle: .alert)
                     
        let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
        alert.addAction(okAction)
                     
        self.currentVC.present(alert, animated: true, completion: nil)
    }
    
    func getGPSSuccess(latitude: Double, longitude: Double) {
        location.stopLocation()
//        if (self.isOnece) {
            print("lng: \(longitude) lat: \(latitude)")
            let param = "\(longitude),\(latitude)"
//            self.isOnece = false
//        }
        gpsClosure?(longitude, latitude)
    }
    
    func getGPSFailure(error: Error) {
//        self.isOnece = false
        print("getMoLocation error: \(error.localizedDescription)")
//        if (!self.isOnece) {
            location.stopLocation()
//        }
    }
    
    func getLocationSuccess(_ area: String, _ locality: String, _ subLocality: String, _ thoroughfare: String, _ name: String) {
        locationClosure?(area,locality,subLocality,thoroughfare,name)
    }
}
